/*---------------------------------------------------------------------------*\
**
**								Heroes IV
**					  Copyright 2000, The 3DO Company
**
** 						       army_dialog_base.h
**
**	$Header: /game/army_dialog.h $
**
**	$NoKeywords: $
**
\*---------------------------------------------------------------------------*/

#ifndef ARMY_DIALOG_BASE_H_INCLUDED
#define ARMY_DIALOG_BASE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#pragma warning( disable: 4786 )

#include <map>
#include <vector>
#include "army.h"
#include "army_array_ptr.h"
#include "artifact_icon_ptr.h"
#include "artifact_slot.h"
#include "bitmap_layer_window.h"
#include "bitmap_layer_window_ptr.h"
#include "bitmap_group_ptr.h"
#include "button_group.h"
#include "creature_array_window.h"
#include "creature_array_window_ptr.h"
#include "drag_artifact_source_holder.h"
#include "skill_icon_ptr.h"
#include "text_window_ptr.h"
#include "toggle_button_ptr.h"

class t_adventure_frame;
class t_adv_artifact_pile;
class t_button;
class t_combat_model_window;
class t_creature_array;
class t_bitmap_layer_cache_window;
enum  t_creature_type;
class t_drag_artifact;
class t_drag_artifact_source;
class t_hero;
class t_luck_icon_window;
class t_morale_icon_window;
struct t_spellbook_window_data;
class t_scrollbar;
class t_town;

// -----------------------------------------------------------------------
// dialog to manipulate one or two armies
// -----------------------------------------------------------------------
class t_army_dialog_base : public t_bitmap_layer_window, public t_drag_artifact_source_holder
{
public:
	t_army_dialog_base( t_creature_array* creatures, t_army* adjacent_army, t_adventure_frame* adventure_frame,
						int selected_slot = -1 );

	virtual void	accept_artifact_drag( t_drag_artifact* drag, t_drag_artifact_source* dest );
	virtual void	artifact_accepted( t_drag_artifact_source * source, t_window * target );
	virtual void	begin_artifact_drag( t_drag_artifact_source* source );
	bool			can_accept( t_drag_artifact* drag, t_drag_artifact_source* dest ) const;
	virtual bool	menu_click( int id );
	void			restore( t_drag_artifact_source* source );
	virtual void	update_artifacts();
	void			update_statistics();

protected:
	typedef std::map<t_army*, t_army*> t_army_map;

	void					backpack_down_click( t_button* button );
	void					backpack_up_click( t_button* button );
	void					biography_click( t_button* button );
	void					cancel_divide_mode();
	virtual bool			cast_spell( t_spellbook_window_data const& spell_data ) const;
	bool					check_for_allied();
	void					close_click( t_button* button );
	virtual void			close_creature_windows();
	void					create_artifact_icons();
    void					create_hero_artifact_icons();
	t_button*				create_button( std::string const& name, t_bitmap_group* layout_ptr = 0 );
	void					create_buttons();
	void					create_creature_windows();
	void					create_icons();
	void					create_skill_icons();
	void					create_text_boxes();
	t_toggle_button*		create_toggle_button( std::string const& name );
	void					divide_clicked( t_button* button );
	void					dismiss_creature( t_button* button );
	void					formation_loose( t_button* button );
	void					formation_square( t_button* button );
	void					formation_tight( t_button* button );
	t_adventure_frame&		get_adventure_frame() const;
	virtual void			get_artifact_pile_position( t_adv_map_point & point, t_counted_ptr< t_adv_artifact_pile > & pile ) = 0;
	t_creature_array*		get_selected_army() const;
	int						get_selected_slot() const;
	t_stack_with_backpack*	get_selected_stack();
	virtual void			get_transfer_costs( int & cost_in, int & cost_out ) const;
	void					handle_selected_stack_removal();
    void                    hide_potions( t_button* button );
	void					highlight_artifact_slots();
	virtual bool			is_restricted( bool visiting_army ) const;
	bool					is_restricted( t_creature_array const * army ) const;
	void					move_down_clicked( t_button* );
	void					move_up_clicked( t_button* );
	virtual void			on_close();
    void                    scrollbar_move( t_scrollbar* scrollbar, int value );
	void					select( t_creature_array_window* window, int slot );
	void					select_leader();
	void					set_artifact_icons( t_creature_stack& stack );
	void					set_skill_icons( t_hero const* hero );
	void					set_skill_icons( t_creature_type creature );
	void					spellbook_click( t_button* );

	enum
	{
		k_skill_rows = 5,
		k_skill_columns = 4,
		k_backpack_size = 10
	};

	t_army*						m_adjacent_army;
	t_creature_array_window_ptr m_adjacent_army_window;
	t_adventure_frame*			m_adventure_frame;
	t_window_ptr                m_ammo_icon;
	std::vector<t_screen_point> m_army_window_position;
	t_creature_array_window_ptr m_army_window;
	std::vector<t_bitmap_layer_window*> m_army_window_list;
	std::vector<t_creature_stack*>   m_army_leader_list;
	t_drag_artifact_source *    m_artifact_sources[k_artifact_slot_hero_count];
	t_drag_artifact_source*     m_backpack[ k_backpack_size ];
	t_button_ptr                m_backpack_down;
	t_button_ptr                m_backpack_up;
	int                         m_backpack_start;
	t_scrollbar*                m_backpack_scrollbar;
	bool                        m_backpack_hide_potions;
	t_button_ptr                m_biography_button;
	t_text_window_ptr           m_class;
	t_combat_model_window*      m_creature_animation;
	t_creature_array*			m_creatures;
	t_bitmap_window_ptr			m_creature_background;
	t_text_window_ptr           m_creature_text;
	t_window_list               m_creature_windows;
	t_luck_icon_window*			m_creature_luck_icon;
	t_text_window*              m_creature_luck_text;
	t_morale_icon_window*		m_creature_morale_icon;
	t_text_window*              m_creature_morale_text;
	t_text_window_ptr           m_damage;
	t_button_ptr                m_dismiss_button;
	t_text_window_ptr           m_experience;
	t_window_ptr                m_experience_icon;
	t_button_group				m_formation_group;
	t_text_window_ptr				m_health;
	t_bitmap_window_ptr				m_hero_background;
	t_bitmap_window_ptr				m_hero_inventory;
	t_bitmap_group_ptr				m_hero_inventory_bitmap;
	t_window_list					m_hero_windows;
	t_button_ptr                    m_hide_potions_button;
	t_button_ptr                    m_show_potions_button;
	t_window_ptr					m_highlight[k_artifact_slot_hero_count];
	bool							m_keyboard_on_adjacent_army;
	t_bitmap_group_ptr				m_layout;
	t_text_window_ptr               m_melee;
	t_window_ptr                    m_melee_attack_icon;
	t_text_window_ptr               m_melee_defense;
	t_window_ptr                    m_melee_defense_icon;
	t_button*						m_move_down_button;
	t_button*						m_move_garrison_down_button;
	t_button*						m_move_tombstone_down_button;
	t_button*						m_move_tombstone_up_button;
	t_button*						m_move_up_button;
	t_text_window_ptr				m_movement;
	t_text_window_ptr				m_name;
	t_bitmap_layer_cache_window*	m_portrait;
    t_button_ptr                    m_portrait_button;
	t_text_window_ptr               m_ranged_attack;
	t_window_ptr                    m_ranged_attack_icon;
	t_text_window_ptr               m_ranged_defense;
	t_window_ptr                    m_ranged_defense_icon;
	t_window_ptr					m_ring_background;
	t_creature_array*           m_selected_creature_array;
	t_creature_array_window*    m_selected_window;
	int                         m_selected_slot;
	t_text_window_ptr           m_shots;
	t_window_ptr                m_shots_icon;
	t_skill_icon_ptr            m_skills[k_skill_rows][k_skill_columns];
	t_text_window_ptr           m_speed;

	t_text_window_ptr           m_spell_points;
	t_window_ptr                m_spell_points_icon;
	t_button_ptr                m_spellbook_button;
	t_toggle_button_ptr         m_split_button;
};

inline t_adventure_frame& t_army_dialog_base::get_adventure_frame() const
{
	assert( m_adventure_frame != 0 );
	return *m_adventure_frame;
}

inline t_creature_array* t_army_dialog_base::get_selected_army() const
{
	return m_selected_creature_array;
}

inline int t_army_dialog_base::get_selected_slot() const
{
	return m_selected_slot;
}


class t_army_dialog_town : public t_army_dialog_base
{
public:
	t_army_dialog_town( t_creature_array* creatures, t_army* adjacent_army, t_adventure_frame* adventure_frame,
		           t_creature_array* selected_creatures, t_town *town_ptr, int selected_slot = -1 );
    
protected:
	virtual void			get_artifact_pile_position( t_adv_map_point & point, t_counted_ptr< t_adv_artifact_pile > & pile );
	
    t_town *                m_town;
};

#endif // ARMY_DIALOG_H_INCLUDED

